package com.yuda.tools.checkanswer.utils;

import cn.hutool.extra.ssh.JschUtil;
import cn.hutool.extra.ssh.Sftp;
import com.jcraft.jsch.Session;

import java.io.File;
import java.nio.charset.StandardCharsets;

public class DeploymentUtils {

    public static void upload(String localFilePath, String remoteFilePath, Sftp sftp) {
        System.out.println("正在上传文件===> " + localFilePath);
        boolean exist = sftp.exist(remoteFilePath.substring(0, remoteFilePath.lastIndexOf("/")));
        if (!exist) {
            sftp.mkdir(remoteFilePath.substring(0, remoteFilePath.lastIndexOf("/")));
        }

        sftp.upload(remoteFilePath, new File(localFilePath));
        System.out.println("上传文件完毕...");
    }

    public static void close(Sftp sftp) {
        if (sftp != null) {
            sftp.close();
        }
    }


}
